package com.june.myfps1

import android.content.Context
import android.os.Bundle
import android.view.Surface
import android.view.SurfaceHolder
import android.view.SurfaceView
import androidx.appcompat.app.AppCompatActivity
import com.june.myfps1.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        /*
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        // Example of a call to a native method
        binding.sampleText.text = stringFromJNI()*/
        setContentView(VulkanSurfaceView(this))
    }

    /**
     * A native method that is implemented by the 'myfps1' native library,
     * which is packaged with this application.
     */
    external fun stringFromJNI(): String
    external fun cleanup()
    external fun drawFrame()
    external fun initVulkan(f: Surface)

    companion object {
        // Used to load the 'myfps1' library on application startup.
        init {
            System.loadLibrary("myfps1")
        }

    }

    inner class VulkanSurfaceView(context: Context?) : SurfaceView(context),
        SurfaceHolder.Callback {
        init {
            holder.addCallback(this)
        }

        override fun surfaceCreated(holder: SurfaceHolder) {
            initVulkan(holder.surface)
        }

        override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
            drawFrame()
        }

        override fun surfaceDestroyed(holder: SurfaceHolder) {
            cleanup()
        }
    }

}